package app.boot;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.*;

import java.lang.Object;

public class BaseFunction {
    public static ArrayList<String> getScript(String path) throws Exception {
        FileReader fileReader = new FileReader(path);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        ArrayList<String> arrayList = new ArrayList<>();
        while (true)
        {
            String line = bufferedReader.readLine();
            if (line == null) {
                break;
            }
            arrayList.add(line);
        }
        bufferedReader.close();
        fileReader.close();
        return arrayList;
    }

    public static String getFileContent(String path) throws Exception {
        FileReader fileReader = new FileReader(path);
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        StringBuffer stringBuffer = new StringBuffer();
        while (true)
        {
            String line = bufferedReader.readLine();
            if (line == null) {
                break;
            }
            stringBuffer.append(line);
            stringBuffer.append("\n");
        }
        bufferedReader.close();
        fileReader.close();
        return stringBuffer.toString();
    }

    public static String getTime() {
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(year);
        stringBuffer.append(month);
        stringBuffer.append(day);
        stringBuffer.append(hour);
        stringBuffer.append(minute);
        stringBuffer.append(second);
        return stringBuffer.toString();
    }
    public static String input(String text) {
        System.out.print(text);
        Scanner scanner = new Scanner(System.in);
        return scanner.nextLine();
    }
    public static String getLastName(String str) {
        try {
            return str.substring(0,str.lastIndexOf("."));
        }catch (Exception exception) {
            return str;
        }
    }
    public static long getRandomLong() {
        Random random = new Random();
        return random.nextLong();
    }

    public static List<String> getAllFilePaths(String directoryPath) {
        List<String> filePaths = new ArrayList<>();
        File directory = new File(directoryPath);

        // 确保提供的路径是目录
        if (directory.isDirectory()) {
            // 获取目录中的所有文件和文件夹
            File[] files = directory.listFiles();
            if (files != null) {
                for (File file : files) {
                    // 将当前文件或文件夹的路径添加到列表中
                    filePaths.add(file.getAbsolutePath());

                    // 如果是目录，则递归调用该方法
                    if (file.isDirectory()) {
                        filePaths.addAll(getAllFilePaths(file.getAbsolutePath()));
                    }
                }
            }
        }

        return filePaths;
    }

}
